﻿using System.Threading.Tasks;
using Jinjia.Approve.Entity.Entity.JJFlow;
using Jinjia.Approve.IRepository.JJFlow;
using Jinjia.Core.UnitOfWork.UnitOfWorkComponent;
using SqlSugar;

namespace Jinjia.Approve.Repository.JJFlow
{
    public class FlowDesignHistoryRepository : IFlowDesignHistoryRepository
    {
        private readonly ISqlSugarClient _db;

        public FlowDesignHistoryRepository(IUnitOfWork unitOfWork)
        {
            _db = unitOfWork.GetDbClient();
        }
        
        public async Task<int> Save(jj_flow_design_history_tbl data)
        {
            if (data.id <= 0) //新增
            {
                var id = await _db.Insertable(data).ExecuteReturnIdentityAsync();
                return id;
            }
            else
            {
                await _db.Updateable(data)
                    .Where(x => x.id == data.id)
                    .ExecuteCommandAsync();
                return data.id;
            }
        }
    }
}